let app = getApp();
let API_URL = app.globalData.API_URL;
import { getNotificationDetailed } from "../../../../request/api.js";
import dayjs from "../../../../common/js/dayjs.js"
let iconUrl = 'https://atush.vip/static/icons/';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        lang: null,
        postId: null,
        noticeDetailed: [],
        iconUrl: iconUrl
    },

    // 获取内容
    getPost() {
        let data = { postId: this.data.postId }
        getNotificationDetailed(res => {
            let request = res.data
            if (res.statusCode == 200) {
                let time = res.data
                time.releaseTime = dayjs(time.releaseTime).format("YYYY-MM-DD")
                this.setData({ noticeDetailed: request })
            }
        }, data);
    },

    // 发送阅读
    sendRead() {
        let notification_id = this.data.postId
        let read = 1
        let data = { notification_id, read }
        wx.request({
            url: `${API_URL}/readNotification`,
            header: app.header(),
            data: data,
            method: 'post',
            success: function (res) {}
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({ lang: app.globalData.lang, postId: options.postId, navTitle: "noticeDetailed", navigation: true })
        this.getPost()
        this.sendRead()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})